
import Vue from 'vue'
import Router from 'vue-router'
import VueRouter from 'vue-router'
Vue.use(Router)
const routes = [
    {
        path:'/',
        redirect:'/login'
    },
    {
        path:'/login',
        name:'Login',
        component:resolve=>require(['@/view/login'],resolve),
        //路由元信息
        meta:{},
    },
    {
        path:'/index',
        name:'Index',
        component:resolve=>require(['@/view/index'],resolve),
        children:[
            {
                path:'/home',
                name:'Home',
                component:resolve=>require(['@/view/home'],resolve),
                meta:{index:'1',requiresAuth:true}
            },
            {
                path:'/blogmanage',
                name:'BlogManage',
                component:resolve=>require(['@/view/blogs'],resolve),
                meta:{index:'2',requiresAuth:true}
            },
            {
                path:'/usermanage',
                name:'User',
                component:resolve=>require(['@/view/users'],resolve),
                meta:{index:'3',requiresAuth:true}
            },
            {
                path:'/category',
                name:'Category',
                component:resolve=>require(['@/view/category'],resolve),
                meta:{index:'4',requiresAuth:true}
            },
            {
                path:'/add',
                name:'add',
                component:resolve=>require(['@/view/addData'],resolve),
                meta:{index:'5',requiresAuth:true}
            },
            {
                path:'/count',
                name:'count',
                component:resolve=>require(['@/view/count'],resolve),
                meta:{index:'6',requiresAuth:true}
            }
        ]
    }
]
const router = new VueRouter({
    mode:"history",
    base:process.env.BASE_URL,
    routes
})
// router.beforeEach((to, from, next) => {
//     console.log('路由:'+to);
  
//     // 需要登录才允许进入路由
//     if(to.meta.requiresAuth){
//         // 判断是否登录
//         if(localStorage.getItem('user')){
//             next();
//         }else{
//             next({
//                 path:'/login'
//             })
//         }
//     }else{
//         // 调用next()方法，放行路由跳转
//         next();
//     }
  
//   });

export default router;